package com.atm.servlet;

import com.atm.pojo.PageBean;
import com.atm.pojo.RunMessage;
import com.atm.pojo.User;
import com.atm.service.RunMessageService;
import com.atm.service.UserService;
import com.atm.service.impl.RunMessageServiceImpl;
import com.atm.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/serchDetaile")
public class SerchDetaileServlet extends HttpServlet {
  private RunMessageService runMessageService=new RunMessageServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String icno;
        if (req.getSession().getAttribute("ua")!=null){
            User user=(User)req.getSession().getAttribute("ua");
            icno = user.getIcno();
            List<RunMessage> runMessageList=runMessageService.findAllDetails(icno);
            //分页处理
            String pageNum = req.getParameter("pageNum");
            int page=1;
            if (pageNum != null){
                page=Integer.parseInt(pageNum);
            }
            //每页显示条数
            int pageSize=5;
            int totalRecord=runMessageList.size();
            PageBean<RunMessage> pageBean = new PageBean<>(page, pageSize, totalRecord);
            List<RunMessage> list=runMessageService.findRunMessageByPage(icno,page,pageSize);
            pageBean.setList(list);
            req.getSession().setAttribute("pageBean",pageBean);
            req.getSession().setAttribute("RunMessage",pageBean.getList());
            resp.sendRedirect("/changepage/UserDetaile.jsp");
        }

    }
}
